package cn.wolfcode.edu.service.impl;

import cn.wolfcode.edu.domain.Employee;
import cn.wolfcode.edu.domain.ExpenseBook;
import cn.wolfcode.edu.mapper.ExpenseBookMapper;
import cn.wolfcode.edu.query.ExpenseBookQueryObject;
import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.service.IExpenseBookService;
import cn.wolfcode.edu.util.PageResult;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.SecurityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by ASUS on 2018/7/9.
 */
@Service
public class ExpenseBookServiceImpl implements IExpenseBookService {


    @Autowired
    private ExpenseBookMapper expenseBookMapper;

    @Override
    public PageResult query(ExpenseBookQueryObject qo) {

       List<ExpenseBook> list= expenseBookMapper.queryForList(qo);
       int total=expenseBookMapper.queryForRows();
        return  new PageResult(total,list);
    }
    @Override
    public void changeStatusById(Long id) {//选中行的id
        //获取当前登录用户审核人
        Employee employee = (Employee) SecurityUtils.getSubject().getPrincipal();
        expenseBookMapper.chanageStatus(id,employee.getId());//更改审核状态
    }

    @Override
    public void saveExpenseBook(ExpenseBook expenseBook) {
        //获取当前登录用户
        Employee employee = (Employee) SecurityUtils.getSubject().getPrincipal();
        expenseBook.setApplyEmp(employee);
        //获取当前当前时间
        expenseBook.setApplyTime(new Date());
        expenseBookMapper.insert(expenseBook);
    }

    public List selectAll(ExpenseBookQueryObject qo) {
        return expenseBookMapper.selectAll(qo);
    }

}
